#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi
 
 

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_zfs.info <<%EOF%
   rsp_zfs
   --------
   Molecule:         O2
   Wave Function:    HSROHF
   Test Purpose:     Zero-field splitting (spin-spin coupling)
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_zfs.mol <<%EOF%
BASIS
cc-pVDZ
Test1 i test-suite: Geometrioptimering med symmetri, med beregning av
egenskaper i foerste og siste punkt. Generelt kontraherte basissett
    1              
        8.    2
O     0.00000000     0.00000000     1.1405
O     0.00000000     0.00000000    -1.1405
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_zfs.dal <<%EOF%
**DALTON
.RUN RESPONSE
**WAVE FUNCTION
.HF
*SCF INPUT
.DOUBLY
 3 1 1 0 2 0 0 0
.SINGLY
 0 0 0 0 0 1 1 0
**RESPONSE
*ESR
.ZFS
**END OF
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_zfs.check
cat >>rsp_zfs.check <<'%EOF%'
log=$1
 
if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Basis set
CRIT1=`$GREP "O * 2 * 8\.0000 * 26 * 14 * \[9s4p1d\|3s2p1d\]" $log | wc -l`
CRIT2=`$GREP "total\: * 2 * 16\.0000 * 52 * 28" $log | wc -l`
CRIT3=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=3
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 6" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * 1\.1405000000" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * \-1\.1405000000" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7`
CTRL[2]=7
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 1 * 1 * 1 * 0 * 1 * 1 * 1 * 0" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 7 * 3 * 3 * 1 * 7 * 3 * 3 * 1" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-149\.608171287[4-5][0-9][0-9]" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="ENERGY NOT CORRECT"

# Zero-field splitting
CRIT1=`$GREP "\@ZFS parameter D = * 1.5093.. cm\-1" $log | wc -l`
CRIT2=`$GREP "\@ZFS parameter E = *0*.000000 cm\-1" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2`
CTRL[5]=2
ERROR[5]="ZERO-FIELD-SPLITTING NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
